<?php

// 9/12/2009: immanuel192 write this function
// this function will trim a string to fit it length

function smarty_function_trim_name_to_fix($params,&$smarty) {
	$st='';
	if (isset($params['text']))
	 $st=trim($params['text']);
	$length=0;
	if (isset($params['length'])) 
	 $length=trim($params['length']);
	else $length=99999;
	if (strlen($st) <= $length)
	 return $st;
	else{
    $pos=$length;
    
    $temp = strrpos($st, " ", $pos);
    // search space char from $length downto 0
    while ($st[$pos] != ' '){
      if ($pos<0)
        break;
      $pos--;
    }
    if ($pos<0) $pos=$length;
    $st=substr($st, 0, $pos) . '..';
    return $st;
  }
}

?>
